package dk.hewison.client.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * An Album or Folder.
 *
 * @author John Hewison
 * @author $LastChangedBy: john.hewison $:  $ $LastChangedDate: 2009-02-04 20:02:52 +0000 (Wed, 04 Feb 2009) $:
 * @version $Revision: 360 $:
 */
public class Directory implements Serializable {

    String folderName;

    Date date;

    List<Photo> photos = new ArrayList<Photo>();
    List<Directory> subDirectories = new ArrayList<Directory>();

    String coverPhotoName;

    Photo coverPhoto;
    private String absolutePath = ".";

    private boolean loaded;
    private Directory parentDirectory;


    public Directory(String folderName) {
        this.folderName = folderName;
    }

    public String getFolderName() {
        return folderName;
    }


    public Date getDate() {
        return date;
    }

    public List<Photo> getPhotos() {
        return photos;
    }

    public Photo getCoverPhoto() {
        return coverPhoto;
    }

    public void setFolderName(String folderName) {
        this.folderName = folderName;
    }


    public void setDate(Date date) {
        this.date = date;
    }

    public void setPhotos(List<Photo> photos) {
        this.photos = photos;
    }

    public void setCoverPhoto(Photo coverPhoto) {
        this.coverPhoto = coverPhoto;
    }

    public String getCoverPhotoName() {
        return coverPhotoName;
    }

    public void setCoverPhotoName(String coverPhotoName) {
        this.coverPhotoName = coverPhotoName;
    }

    public List<Directory> getSubDirectories() {
        return subDirectories;
    }


    public boolean isLoaded() {
        return loaded;
    }

    public void setLoaded() {
        loaded = true;
    }

    public void add(Directory subDirectory) {
        subDirectories.add(subDirectory);
        subDirectory.setParentDirectory(this);
    }

    private void setParentDirectory(Directory directory) {
        this.parentDirectory = directory;
        absolutePath = parentDirectory.getAbsolutePath() + "/" + folderName;
    }

    public Directory getParentDirectory() {
        return parentDirectory;
    }

    @Override
    public String toString() {
        return "Directory{" +
                "folderName='" + folderName + '\'' +
                ", date=" + date +
                ", photos=" + photos +
                ", subDirectories=" + subDirectories +
                ", coverPhotoName='" + coverPhotoName + '\'' +
                ", coverPhoto=" + coverPhoto +
                ", absolutePath='" + absolutePath + '\'' +
                ", loaded=" + loaded +
                '}';
    }

    public String getAbsolutePath() {
        return absolutePath;
    }

    public void addPhoto(String imageName) {
        Photo photo = new Photo(getAbsolutePath(), imageName);
        photos.add(photo);
    }
}
